package com.baomidou.springwind.test.IO;

import java.io.*;
import java.util.LinkedList;

/**
 * Created by Administrator on 2017/2/24.
 */
public class BufferedInputFile {
    public static String read(String filename) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(filename));
        StringBuffer stringBuffer = new StringBuffer();
        String s;
        while ((s = bufferedReader.readLine()) != null) {
            stringBuffer.append(s + "\n");

        }
        bufferedReader.close();
        return stringBuffer.toString();
    }

    public static void readToList(String filename, LinkedList<String> linkedList) throws IOException{
        BufferedReader in = new BufferedReader(new FileReader(filename));
        String s;
        while ((s = in.readLine()) != null) {
            linkedList.addFirst(s);
        }
        for (String e : linkedList) {
            System.out.println(e);
        }
        in.close();
    }

    public static void main(String[] args) throws IOException {
//        System.out.println(
//                read("F:\\code\\SpringWind\\SpringWind\\src\\main\\java\\com\\baomidou\\springwind\\test\\IO\\BufferedInputFile.java"));

        LinkedList<String> linkedList = new LinkedList<String>();
        StringBuffer filename = new StringBuffer();
        for (int i = 0; i < args.length; i++) {
            System.out.print(args[i]);
            filename.append(args[i]);
        }
//        readToList(
//                "F:\\code\\SpringWind\\SpringWind\\src\\main\\java\\com\\baomidou\\springwind\\test\\IO\\yhx.txt",linkedList);
        readToList(filename.toString(), linkedList);
    }
}
